// pages/profile/profile.js
Page({
  data: {
    userInfo: {
      avatarUrl: '',
      nickName: '用户123',
      calorieGoal: 2000,
      weight: 65,
      height: 170,
      age: 25,
      gender: '男'
    },
    todayStats: {
      consumed: 450,
      remaining: 1550,
      exercise: 60
    },
    currentDate: ''
  },

  onLoad() {
    console.log('个人中心页面加载');
    this.setCurrentDate();
  },

  onShow() {
    // 页面显示时的逻辑
  },

  // 设置当前日期
  setCurrentDate() {
    const now = new Date();
    const dateStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
    this.setData({
      currentDate: dateStr
    });
  },

  // 修改用户信息
  editProfile() {
    wx.showToast({
      title: '编辑资料功能待开发',
      icon: 'none'
    });
  },

  // 设置热量目标
  setCalorieGoal() {
    wx.showModal({
      title: '设置热量目标',
      editable: true,
      placeholderText: '请输入每日热量目标(kcal)',
      content: this.data.userInfo.calorieGoal.toString(),
      success: (res) => {
        if (res.confirm && res.content) {
          const goal = parseInt(res.content);
          if (goal && goal > 0) {
            this.setData({
              'userInfo.calorieGoal': goal
            });
            wx.showToast({
              title: '设置成功',
              icon: 'success'
            });
          } else {
            wx.showToast({
              title: '请输入有效数字',
              icon: 'error'
            });
          }
        }
      }
    });
  },

  // 查看详细统计
  viewDetailedStats() {
    wx.showToast({
      title: '详细统计功能待开发',
      icon: 'none'
    });
  },

  // 联系客服
  contactSupport() {
    wx.showModal({
      title: '联系客服',
      content: '客服微信：FoodAI_Support\n客服邮箱：support@foodai.com',
      showCancel: false,
      confirmText: '知道了'
    });
  },

  // 意见反馈
  feedback() {
    wx.showToast({
      title: '意见反馈功能待开发',
      icon: 'none'
    });
  },

  // 关于我们
  aboutUs() {
    wx.navigateTo({
      url: '/pages/about/about'
    });
  },

  // 底部导航切换
  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    
    switch (tab) {
      case 'home':
        wx.redirectTo({
          url: '/pages/index/index'
        });
        break;
      case 'history':
        wx.redirectTo({
          url: '/pages/history/history'
        });
        break;
      case 'plan':
        wx.redirectTo({
          url: '/pages/plan/plan'
        });
        break;
      case 'profile':
        // 当前页面，无需跳转
        break;
      default:
        wx.redirectTo({
          url: '/pages/index/index'
        });
    }
  }
})